/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.controller;

import com.minierp.dao.ClieUserDao;
import com.minierp.dao.IdGenerator;
import com.minierp.dao.TallySetDao;
import com.minierp.err.PermissionDennyException;
import com.minierp.helper.EncCommonHelper;
import com.minierp.model.ClieUser;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class ClieUserMACtr extends MultiActionController {
	private ClieUserDao clieUserDao;
	private TallySetDao tallySetDao;
	private IdGenerator idGenerator;
	private String listView;

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public ModelAndView handleList(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		if (!EncCommonHelper.checkPrivilege(request, "CLIE_USER")) {
			throw new PermissionDennyException("Permission denny!");
		} else {
			String searchKey = request.getParameter("search_key");
			ModelAndView mv = new ModelAndView(this.listView);
			List list = this.clieUserDao.getList(false, searchKey);
			mv.addObject("list", list);
			mv.addObject("tsList", this.tallySetDao.getList(false));
			return mv;
		}
	}

	public ModelAndView handleDelete(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String returnUrl = request.getParameter("from_url");
		String id = request.getParameter("id");
		if (!EncCommonHelper.checkPrivilege(request, "CLIE_USER")) {
			throw new Exception("Permission deny!");
		} else {
			this.clieUserDao.delete(Long.parseLong(id));
			EncCommonHelper.setAlertMessage(request, "删除成功！");
			return new ModelAndView("redirect:" + returnUrl);
		}
	}

	public ModelAndView handlePause(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String returnUrl = request.getParameter("from_url");
		String id = request.getParameter("id");
		String flag = request.getParameter("flag");
		if (!EncCommonHelper.checkPrivilege(request, "CLIE_USER")) {
			throw new Exception("Permission deny!");
		} else {
			ClieUser u = (ClieUser) this.clieUserDao.get(ClieUser.class,
					Long.parseLong(id));
			if (u != null) {
				u.setEnabled(flag);
				this.clieUserDao.update(u);
			}

			EncCommonHelper.setAlertMessage(request, "设置成功！");
			return new ModelAndView("redirect:" + returnUrl);
		}
	}

	public String getListView() {
		return this.listView;
	}

	public void setListView(String listView) {
		this.listView = listView;
	}

	public IdGenerator getIdGenerator() {
		return this.idGenerator;
	}

	public void setIdGenerator(IdGenerator idGenerator) {
		this.idGenerator = idGenerator;
	}

	public ClieUserDao getClieUserDao() {
		return this.clieUserDao;
	}

	public void setClieUserDao(ClieUserDao clieUserDao) {
		this.clieUserDao = clieUserDao;
	}
}